package io.renren.modules.lanling.controller;

import java.util.Arrays;
import java.util.Map;

import io.renren.common.validator.ValidatorUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import io.renren.modules.lanling.entity.ExamDatailsEntity;
import io.renren.modules.lanling.service.ExamDatailsService;
import io.renren.common.utils.PageUtils;
import io.renren.common.utils.R;

import static io.renren.modules.sys.shiro.ShiroUtils.getUserId;


/**
 * 考试详情表
 *
 * @author LANLING
 * @email lanling@gmail.com
 * @date 2018-10-24 10:40:05
 */
@RestController
@RequestMapping("lanling/examdatails")
public class ExamDatailsController {
    @Autowired
    private ExamDatailsService examDatailsService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("lanling:examdatails:list")
    public R list(@RequestParam Map<String, Object> params) {
        Long userId = getUserId();
        params.put("createUserId", userId);
        PageUtils page = examDatailsService.queryPage(params);

        return R.ok().put("page", page);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{id}")
    @RequiresPermissions("lanling:examdatails:info")
    public R info(@PathVariable("id") Integer id) {
        ExamDatailsEntity examDatails = examDatailsService.selectById(id);

        return R.ok().put("examDatails", examDatails);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("lanling:examdatails:save")
    public R save(@RequestBody ExamDatailsEntity examDatails) {
        examDatailsService.insert(examDatails);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("lanling:examdatails:update")
    public R update(@RequestBody ExamDatailsEntity examDatails) {
        ValidatorUtils.validateEntity(examDatails);
        examDatailsService.updateAllColumnById(examDatails);//全部更新

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("lanling:examdatails:delete")
    public R delete(@RequestBody Integer[] ids) {
        examDatailsService.deleteBatchIds(Arrays.asList(ids));

        return R.ok();
    }

}
